
package com.visikard.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.visikard.application.Constant;
import com.visikard.application.UIMessage;
import com.visikard.application.VKRegApplication;
import com.visikard.asynctask.BaseTask;
import com.visikard.asynctask.RequestRTUICouponTask;
import com.visikard.ui.R;
import com.visikard.utility.Utils;

public class RequestRTUICouponActivity extends BaseLoginCompleteActivity implements OnClickListener {

	private Context mContext;
	private Button btnBack, btnRequest;
	private EditText couponTitle, contract, message;
	private RelativeLayout parent;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rtui_send_request_coupon_activity);
		
		mContext = this;
		initView();
	}
	
	private void initView() {
		parent = (RelativeLayout) findViewById(R.id.wrapper_rtui_send_request_coupon);
		couponTitle = (EditText) findViewById(R.id.rtui_coupon_title);
		contract = (EditText) findViewById(R.id.rtui_contract_number);
		message = (EditText) findViewById(R.id.rtui_your_message);
		btnBack = (Button) findViewById(R.id.rtui_btn_back_request);
		btnRequest = (Button) findViewById(R.id.rtui_btn_send_request);
		Utils.overrideFonts(parent, Constant.FONT_GOTHAM_BOOK);
		btnBack.setOnClickListener(this);
		btnRequest.setOnClickListener(this);
	}

		
	@Override
	public void onPause() {
		super.onPause();
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}
	
	@Override
	public void onBackPressed() {
		finish();
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.rtui_btn_back_request:
				finish();
				break;
			case R.id.rtui_btn_send_request:
				doSendRequestCoupon();
				break;
			default:
				break;
		}

	}
	
	protected void doSendRequestCoupon(){
		String _title = couponTitle.getText().toString().trim();
		String _contract = contract.getText().toString().trim();
		String _message = message.getText().toString().trim();
		
		if(_title.isEmpty()){
			Utils.showToast(mContext, R.string.rtui_error_message_coupon_title);
			return;
		}
		if(_contract.isEmpty()){
			Utils.showToast(mContext, R.string.rtui_error_message_contract);
			return;
		}
		if(_message.isEmpty()){
			Utils.showToast(mContext, R.string.rtui_error_message_message);
			return;
		}
		
		BaseTask task = new RequestRTUICouponTask(mHandler);
		task.execute(VKRegApplication.merchantAccountObj.getIdUsersMerchant(), _title, _contract, _message);
		
	}
	@Override
	public boolean handleMessage(Message msg) {
		switch (msg.what) {
			case UIMessage.MSG_REQUEST_RTUI_COUPON_SUCCESS:
				Utils.showToast(mContext, R.string.rtui_request_coupon_success);
				return true;
			case UIMessage.MSG_REQUEST_RTUI_COUPON_FAILED:
				Utils.showToast(mContext, R.string.rtui_request_coupon_fail);
				return true;
			
		}
		return super.handleMessage(msg);
	}
	

}
